<template>
   <div>
        <el-form   :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

            <el-form-item label="岗位编码" prop="Code">
                <el-input v-model="model.Code"></el-input>
            </el-form-item>

            <el-form-item label="岗位名称" prop="Name">
                <el-input v-model="model.Name"></el-input>
            </el-form-item>
            <el-form-item label="显示顺序" prop="Sort">
                <el-input-number v-model="model.Sort"></el-input-number>
            </el-form-item>

            <el-form-item label="状态" prop="Status">
                <el-radio-group v-model="model.Status">
                    <el-radio label="0">正常</el-radio>
                    <el-radio label="1">停用</el-radio>
                </el-radio-group>
            </el-form-item>
            
            <el-form-item label="备注" prop="Remark">
                <el-input v-model="model.Remark"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    props: {
        model: {
            require: true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean
        }
    },
    data() {
        return {
            SystemPostList:[],
            rules: {
                Name: { required: true, message: '请输入岗位编码', trigger: 'blur' },
                Code: { required: true, message: '请输入岗位名称', trigger: 'blur' },
                Sort: { required: true, message: '请输入显示顺序', trigger: 'blur' },
                Status: { required: true, message: '请选择状态', trigger: 'blur' },
            }
        }
    },
    created(){
        this.getSystemPostAll();
    },  
    methods:{
        submitForm() {
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {

                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }

                } else {
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
      },
      resetForm() {
        this.$refs['ruleForm'].resetFields();
      },
      add(){
        this.$http.postForm('/api/SystemPost',{model:this.model},{loading:this.$loading()})
        .then(res=>{
            this.$emit('callback');
        })

      },
      //修改
      put(){
        this.$http.putForm('/api/SystemPost',{model:this.model},{loading:this.$loading()})
		.then((res)=>{
            this.$emit('callback');
		})
      },

      getSystemPostAll(){
        this.$http.get('/api/SystemPost/GetAll')
        .then(res=>{
            console.log(res);
            this.SystemPostList=res.Data ;
        })
      }
    }

}
</script>

<style>

</style>